<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title>
  <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <p>天气预</p>
    <button @click="isHot=!isHot">改变天气</button>
    <p>今天的天气真的{{isHot?'热':'冷'}}啊</p>
    <img :src="src" alt="">
  </div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false;
  const vm = new Vue({
    el: "#app",
    data() {
      return {
        isHot: true,
        // src: './re.webp',
        src: "",
        count: 0
      }
    },
    watch: {
      //监听属性
      isHot: {
        //在初始化的时候执行一次函数
        immediate: true,
        //当被监听的isHot发生改变的时候,handler函数就会执行
        //可以在函数中 现在的值 之前的值
        handler(now, pre) {
          console.log(now, pre);
          now ? this.src = "./leng.webp" : this.src = "./re.webp"
          // this.src = now ? "./re.webp" : "./leng.webp"

        }
      }
    }
  })
</script>

</html>